﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Configuration.Install;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MediaLibraryManagement
{
    [RunInstaller(true)]
    public partial class InstallerUtility : System.Configuration.Install.Installer
    {
        public InstallerUtility()
        {
            InitializeComponent();
        }

        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
            string targetDirectory = Context.Parameters["targetdir"];
            string databaseServer = Context.Parameters["dbserver"];
            string executionPath = string.Format("{0}MediaLibraryManagement.exe", targetDirectory);
            Configuration config = ConfigurationManager.OpenExeConfiguration(executionPath);
            string connectionString = config.ConnectionStrings.ConnectionStrings["MediaLibraryManagement.Properties.Settings.ConnectionString"].ConnectionString;
            config.ConnectionStrings.ConnectionStrings["MediaLibraryManagement.Properties.Settings.ConnectionString"].ConnectionString = connectionString.Replace("[DBSERVER]", databaseServer);
            config.Save();
        }
    }
}
